home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / RCP.jar / com / extensibility / app / BaseApplication.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-03  |  14.2 KB  |  596 lines

  1. package com.extensibility.app;
  2.  
  3. import com.extensibility.app.plugin.URIResourcePlugin;
  4. import com.extensibility.plugin.PluginRegistry;
  5. import com.extensibility.plugin.api.ApplicationAccess;
  6. import com.extensibility.rock.AltGrPatch;
  7. import com.extensibility.rock.Platform;
  8. import com.extensibility.rock.RDialog;
  9. import com.extensibility.util.Debug;
  10. import com.extensibility.util.Security;
  11. import com.extensibility.xml.URI;
  12. import com.extensibility.xml.URIFileScheme;
  13. import com.extensibility.xml.URIStringScheme;
  14. import com.extensibility.xml.URIUrlScheme;
  15. import com.extensibility.xml.URIUrnScheme;
  16. import com.extensibility.xml.URIxschemaScheme;
  17. import java.awt.Component;
  18. import java.awt.Font;
  19. import java.awt.Frame;
  20. import java.awt.Window;
  21. import java.awt.event.ActionEvent;
  22. import java.io.File;
  23. import java.io.FileOutputStream;
  24. import java.io.IOException;
  25. import java.io.PrintStream;
  26. import java.io.Writer;
  27. import java.net.URL;
  28. import java.util.Date;
  29. import java.util.Enumeration;
  30. import java.util.EventObject;
  31. import java.util.Vector;
  32. import javax.swing.JFrame;
  33. import javax.swing.JOptionPane;
  34. import javax.swing.UIManager;
  35.  
  36. public abstract class BaseApplication implements Platform.Application {
  37.    static final String PRINT_TEMPLATE = "_print_template";
  38.    protected static BaseApplication oneAndOnly;
  39.    // $FF: renamed from: ui com.extensibility.app.UI
  40.    static UI field_0;
  41.    private final Registration newreg = new Registration(this);
  42.    protected Security registration;
  43.    private ApplicationPreferences prefs;
  44.    protected Vector listeners = new Vector();
  45.    static File homePath;
  46.    private ApplicationAccess pluginAppAccess = new 1();
  47.    BaseAction showHideToolbarAction;
  48.    // $FF: synthetic field
  49.    static Class class$com$extensibility$app$BaseApplication;
  50.  
  51.    public BaseApplication() {
  52.       new AltGrPatch();
  53.       oneAndOnly = this;
  54.    }
  55.  
  56.    public static BaseApplication getApplication() {
  57.       return oneAndOnly;
  58.    }
  59.  
  60.    public static String getPreference(String var0) {
  61.       return getApplication().prefs.getProperty(var0);
  62.    }
  63.  
  64.    public static ApplicationPreferences getPreferences() {
  65.       return getApplication().prefs;
  66.    }
  67.  
  68.    public static String getPreference(String var0, int var1) {
  69.       return getApplication().prefs.getProperty(var0 + var1);
  70.    }
  71.  
  72.    public static UI getUI() {
  73.       return field_0;
  74.    }
  75.  
  76.    public static boolean isDebug() {
  77.       if (getPreferences() != null) {
  78.          return getPreferences().getDebugLevel() > 0;
  79.       } else {
  80.          return true;
  81.       }
  82.    }
  83.  
  84.    public static int getDebugLevel() {
  85.       return getPreferences() != null ? getPreferences().getDebugLevel() : 2;
  86.    }
  87.  
  88.    public static File getHomePath() {
  89.       if (homePath != null) {
  90.          return homePath;
  91.       } else {
  92.          String var0 = System.getProperty("java.class.path");
  93.  
  94.          while(var0 != null) {
  95.             int var2 = var0.indexOf(System.getProperty("path.separator"));
  96.             String var1;
  97.             if (var2 >= 0) {
  98.                var1 = var0.substring(0, var2);
  99.                var0 = var0.substring(var2 + 1);
  100.             } else {
  101.                var1 = var0;
  102.                var0 = null;
  103.             }
  104.  
  105.             if (var1.length() != 0) {
  106.                File var3 = new File(var1);
  107.                if (var3.isDirectory()) {
  108.                   if ((new File(var1, (class$com$extensibility$app$BaseApplication != null ? class$com$extensibility$app$BaseApplication : (class$com$extensibility$app$BaseApplication = class$("com.extensibility.app.BaseApplication"))).getName().replace('.', File.separatorChar) + ".class")).exists()) {
  109.                      homePath = new File(var3.getParent());
  110.                      break;
  111.                   }
  112.                } else if (var3.getName().equalsIgnoreCase(getApplication().getAbbr() + ".jar")) {
  113.                   String var4 = var3.getParent();
  114.                   if (var4 == null) {
  115.                      var4 = System.getProperty("user.dir");
  116.                   }
  117.  
  118.                   homePath = new File(var4);
  119.                   break;
  120.                }
  121.             }
  122.          }
  123.  
  124.          Debug.assert(homePath != null, "Unable to locate home path within " + System.getProperty("java.class.path") + ". Looked for: " + getApplication().getAbbr() + ".jar");
  125.          return homePath;
  126.       }
  127.    }
  128.  
  129.    public void reregister() {
  130.       this.newreg.reregister();
  131.    }
  132.  
  133.    public static Date getExpiration() {
  134.       return Registration.getExpirationDate();
  135.    }
  136.  
  137.    private void register() {
  138.       this.newreg.register();
  139.    }
  140.  
  141.    public void openDocumentList(String[] var1) {
  142.       for(int var2 = 0; var2 < var1.length; ++var2) {
  143.          if (!var1[var2].equals("-quiet")) {
  144.             if (var1[var2].charAt(0) == '"' && var1[var2].charAt(var1[var2].length() - 1) == '"') {
  145.                var1[var2] = var1[var2].substring(1, var1[var2].length() - 1);
  146.             }
  147.  
  148.             this.openDocument(new File(var1[var2]));
  149.          }
  150.       }
  151.  
  152.    }
  153.  
  154.    public void doArgs(String[] var1) {
  155.       if (var1 != null && var1.length > 0 && var1[0].length() > 0) {
  156.          Desktop.createSplash();
  157.          Desktop.createWelcome(false);
  158.          this.openDocumentList(var1);
  159.       } else if (getPreferences().getShowWelcome()) {
  160.          Desktop.createWelcome(true);
  161.          this.preflight();
  162.       } else {
  163.          Desktop.createSplash();
  164.          Desktop.createWelcome(false);
  165.          this.newDocument((EventObject)null);
  166.       }
  167.  
  168.       this.fireApplicationStarted();
  169.    }
  170.  
  171.    protected String[] getSaveTypes() {
  172.       return this.getOpenTypes();
  173.    }
  174.  
  175.    public abstract byte getRegVersion();
  176.  
  177.    protected abstract String[] getOpenTypes();
  178.  
  179.    public abstract BaseDocument createNewDocument(EventObject var1);
  180.  
  181.    public abstract BaseDocument createNewDocument(URI var1);
  182.  
  183.    protected abstract UI createUI();
  184.  
  185.    protected abstract Class getMainWindowClass();
  186.  
  187.    protected abstract BaseWindow createNewWindow(BaseDocument var1);
  188.  
  189.    protected abstract ApplicationPreferences createPreferences();
  190.  
  191.    protected abstract String getAbbr();
  192.  
  193.    public abstract String getVersion();
  194.  
  195.    public RDialog createPreferencesDialog(JFrame var1) {
  196.       return new PreferencesDialog(var1, getPreferences());
  197.    }
  198.  
  199.    public abstract JFrame createWelcome();
  200.  
  201.    public abstract RDialog createPrintDialog(Frame var1);
  202.  
  203.    public void startup() throws Exception {
  204.       field_0 = this.createUI();
  205.       field_0.initResources();
  206.       Platform.initialize(this);
  207.       this.prefs = this.createPreferences();
  208.       this.prefs.readInitial(new File(getHomePath(), this.getAbbr() + "_Preferences"));
  209.       Font var1 = this.prefs.getAppFont();
  210.       if (var1 != null) {
  211.          UI.setAppFont(var1);
  212.       }
  213.  
  214.       var1 = this.prefs.getDocFont();
  215.       if (var1 != null) {
  216.          UI.setDocFont(var1);
  217.       }
  218.  
  219.       var1 = this.prefs.getSrcFont();
  220.       if (var1 != null) {
  221.          UI.setSrcFont(var1);
  222.       }
  223.  
  224.       try {
  225.          String var2 = this.prefs.getLookAndFeel();
  226.          UIManager.setLookAndFeel(var2);
  227.       } catch (Exception var3) {
  228.       }
  229.  
  230.       Debug.setCatcher(this.createCatcher());
  231.       this.doPluginRegistration();
  232.       this.register();
  233.       this.registration = this.newreg.getRegistration();
  234.       if (getDebugLevel() > 1) {
  235.          System.setOut(new PrintStream(new FileOutputStream(new File("console-out.txt"))));
  236.          System.setErr(new PrintStream(new FileOutputStream(new File("console-err.txt"))));
  237.       }
  238.  
  239.       if (this.newreg.isLaunchLimited()) {
  240.          this.prefs.updateLaunchesLeft(this.prefs.getLaunchesLeft() - 1);
  241.       }
  242.  
  243.    }
  244.  
  245.    protected void doPluginRegistration() {
  246.       String var1 = UI.getString("plugin.folder");
  247.       if (var1.startsWith("#MISSING")) {
  248.          var1 = "plugins";
  249.       }
  250.  
  251.       File var2 = new File(getHomePath(), var1);
  252.       PluginRegistry var3 = PluginRegistry.getRegistry();
  253.       var3.setAppAccess(this.pluginAppAccess);
  254.       var3.registerPluginsInFolder(var2);
  255.       URIResourcePlugin.registerPlugin(var3);
  256.       URIFileScheme.registerPlugin(var3);
  257.       URIStringScheme.registerPlugin(var3);
  258.       URIUrlScheme.registerPlugin(var3);
  259.       URIUrnScheme.registerPlugin(var3);
  260.       URIxschemaScheme.registerPlugin(var3);
  261.       URI.registerSchemes();
  262.    }
  263.  
  264.    protected Debug.Catcher createCatcher() {
  265.       return new 2();
  266.    }
  267.  
  268.    public void quit() {
  269.       this.exitApplication((EventObject)null);
  270.    }
  271.  
  272.    public void openAboutWindow() {
  273.       Desktop.createAboutWindow();
  274.    }
  275.  
  276.    public void printDocument(File var1) {
  277.    }
  278.  
  279.    public void exitApplication(EventObject var1) {
  280.       Vector var2 = Desktop.getWindows();
  281.  
  282.       for(int var3 = var2.size() - 1; var3 >= 0; --var3) {
  283.          BaseWindow var4 = (BaseWindow)var2.elementAt(var3);
  284.          if (!var4.getDocument().isOkToClose(var4)) {
  285.             return;
  286.          }
  287.       }
  288.  
  289.       for(int var8 = var2.size() - 1; var8 >= 0; --var8) {
  290.          BaseWindow var5 = (BaseWindow)var2.elementAt(var8);
  291.          ((Frame)var5).dispose();
  292.       }
  293.  
  294.       try {
  295.          this.prefs.save();
  296.       } catch (IOException var6) {
  297.          DialogFactory.showException((Component)null, 108, var6);
  298.       } catch (Throwable var7) {
  299.          Debug.assert(false, "Got a non io error exiting application: " + var7);
  300.       }
  301.  
  302.       this.fireApplicationExited();
  303.       System.exit(0);
  304.    }
  305.  
  306.    private void preflight() {
  307.    }
  308.  
  309.    public static boolean isLaunchLimited() {
  310.       return getApplication().newreg.isLaunchLimited();
  311.    }
  312.  
  313.    public static int getLaunchesLeft() {
  314.       return getApplication().prefs.getLaunchesLeft();
  315.    }
  316.  
  317.    public boolean openDocumentURL(ActionEvent var1) {
  318.       String[] var2 = this.getOpenTypes();
  319.       String var3 = getPreferences().getOpenFromBase();
  320.       URI var4 = null;
  321.       if (var3 != null) {
  322.          var4 = new URI((URI)null, var3);
  323.       }
  324.  
  325.       URI var5 = DialogFactory.openURI(Desktop.getDialogParent(var1), var4, var2);
  326.       if (var5 == null) {
  327.          return false;
  328.       } else {
  329.          this.openDocument(var5);
  330.          return true;
  331.       }
  332.    }
  333.  
  334.    public boolean saveDocumentTo(ActionEvent var1, BaseDocument var2) {
  335.       Object var3 = null;
  336.       String var4 = getPreferences().getSaveToBase();
  337.       URI var5 = var2.getURI();
  338.       String var6 = var5.getFullName();
  339.       if (var6.length() < 0 || var4 != null && var4.length() != 0 && var5.getScheme().equals("file")) {
  340.          String var7 = var2.getName();
  341.          if (var4 == null) {
  342.             var4 = var7;
  343.          } else {
  344.             if (!var4.endsWith("/")) {
  345.                var4 = var4 + "/";
  346.             }
  347.  
  348.             var4 = var4 + var7;
  349.          }
  350.       } else {
  351.          var4 = var6;
  352.       }
  353.  
  354.       URI var12 = new URI((URI)null, var4);
  355.       URI var8 = DialogFactory.saveURI(Desktop.getDialogParent(var1), var12, (String[])var3);
  356.       if (var8 == null) {
  357.          return false;
  358.       } else if (var8.exists() && !DialogFactory.showConfirm((Component)null, UI.getString("stop.uri.exists", var8.getFullName()), UI.getString("dialog.replace.title"))) {
  359.          return false;
  360.       } else {
  361.          try {
  362.             Writer var9 = var2.createWriter(var8);
  363.             var2.write(var9);
  364.             var9.close();
  365.             return true;
  366.          } catch (Exception var10) {
  367.             DialogFactory.showException((Component)null, 103, var10, var8.getShortName());
  368.             return false;
  369.          }
  370.       }
  371.    }
  372.  
  373.    public BaseDocument newDocument(EventObject var1) {
  374.       BaseDocument var2 = this.createNewDocument(var1);
  375.  
  376.       try {
  377.          BaseWindow var3 = this.getMainWindow(var2);
  378.          ((Component)var3).setVisible(true);
  379.       } catch (Exception var5) {
  380.          String var4 = Platform.mapNewlinesForTextArea(Debug.getStackTrace(var5));
  381.          JOptionPane.showMessageDialog(new JFrame(), var4);
  382.          Desktop.ensureWindow();
  383.       }
  384.  
  385.       return var2;
  386.    }
  387.  
  388.    public boolean openDocument(URI var1) {
  389.       BaseDocument var2 = Desktop.getDocument(var1);
  390.       if (var2 != null) {
  391.          DialogFactory.stop((Component)null, UI.getString("stop.already.open", var1.getShortName()));
  392.          Desktop.activateDocument(var2);
  393.          return true;
  394.       } else {
  395.          BaseDocument var3 = this.createNewDocument(var1);
  396.  
  397.          try {
  398.             var3.read(var1);
  399.             this.updateFileLists(var1);
  400.             this.getMainWindow(var3);
  401.             this.fireDocumentOpened(var1);
  402.             return true;
  403.          } catch (Exception var5) {
  404.             DialogFactory.showException((Component)null, 102, var5);
  405.             return false;
  406.          }
  407.       }
  408.    }
  409.  
  410.    public BaseWindow getMainWindow(BaseDocument var1) {
  411.       BaseWindow var2 = var1.getWindow(this.getMainWindowClass());
  412.       if (var2 != null) {
  413.          ((Window)var2).toFront();
  414.          return var2;
  415.       } else {
  416.          var2 = this.createNewWindow(var1);
  417.          Desktop.positionNewWindow(var2);
  418.          var2.initialize(getPreferences());
  419.          Desktop.showNewWindow(var2, true);
  420.          return var2;
  421.       }
  422.    }
  423.  
  424.    public void createAnotherWindow(BaseDocument var1) {
  425.       BaseWindow var2 = this.createNewWindow(var1);
  426.       Desktop.positionNewWindow(var2);
  427.       var2.initialize((ApplicationPreferences)null);
  428.       Desktop.showNewWindow(var2, false);
  429.    }
  430.  
  431.    public boolean openDocument(ActionEvent var1) {
  432.       File var2 = DialogFactory.askFile(Desktop.getDialogParent(var1), UI.getString("dialog.open.schema"), this.getOpenTypes());
  433.       return var2 == null ? false : this.openDocument(new URI(var2));
  434.    }
  435.  
  436.    public void saveNotify(URI var1, BaseDocument var2) {
  437.       Enumeration var3 = Desktop.getDocuments();
  438.  
  439.       while(var3.hasMoreElements()) {
  440.          BaseDocument var4 = (BaseDocument)var3.nextElement();
  441.          if (var4 != var2) {
  442.             var4.saveNotify(var1);
  443.          }
  444.       }
  445.  
  446.       this.fireDocumentSaved(var1);
  447.    }
  448.  
  449.    public void updateFileLists(URI var1) {
  450.       this.prefs.updateRecent(var1);
  451.       this.updateRecentMenu();
  452.       this.updateWindowMenu();
  453.    }
  454.  
  455.    public void removeFromRecent(URI var1) {
  456.       this.prefs.removeFromRecent(var1);
  457.       this.updateRecentMenu();
  458.    }
  459.  
  460.    private void updateWindowMenu() {
  461.       Enumeration var1 = Desktop.getWindows().elements();
  462.  
  463.       while(var1.hasMoreElements()) {
  464.          BaseWindow var2 = (BaseWindow)var1.nextElement();
  465.          var2.fillWindowsMenu();
  466.       }
  467.  
  468.    }
  469.  
  470.    private void updateRecentMenu() {
  471.       Enumeration var1 = Desktop.getWindows().elements();
  472.  
  473.       while(var1.hasMoreElements()) {
  474.          BaseWindow var2 = (BaseWindow)var1.nextElement();
  475.          var2.updateRecentMenuItems();
  476.       }
  477.  
  478.    }
  479.  
  480.    public void updateNewSubMenu() {
  481.       Enumeration var1 = Desktop.getWindows().elements();
  482.  
  483.       while(var1.hasMoreElements()) {
  484.          BaseWindow var2 = (BaseWindow)var1.nextElement();
  485.          String var3 = getPreferences().getDefaultFileType();
  486.          var2.updateNewSubMenuItems(UI.getFileTypeName(var3));
  487.       }
  488.  
  489.    }
  490.  
  491.    public BaseAction createToolbarAction() {
  492.       if (this.showHideToolbarAction == null) {
  493.          this.showHideToolbarAction = new 3(this, "item.tb");
  494.          this.showHideToolbarAction.setSelected(this.prefs.getToolbarView() == 1);
  495.       }
  496.  
  497.       return this.showHideToolbarAction;
  498.    }
  499.  
  500.    private void updateToolBarView(int var1) {
  501.       this.prefs.updateToolBarView(var1);
  502.       Enumeration var2 = Desktop.getWindows().elements();
  503.  
  504.       while(var2.hasMoreElements()) {
  505.          BaseWindow var3 = (BaseWindow)var2.nextElement();
  506.          var3.updateToolBarView();
  507.       }
  508.  
  509.    }
  510.  
  511.    public boolean openDocument(URL var1) {
  512.       return this.openDocument(new URI(var1));
  513.    }
  514.  
  515.    public boolean openDocument(File var1) {
  516.       return this.openDocument(new URI(var1));
  517.    }
  518.  
  519.    public void addApplicationListener(ApplicationListener var1) {
  520.       this.listeners.addElement(var1);
  521.    }
  522.  
  523.    public void removeApplicationListener(ApplicationListener var1) {
  524.       this.listeners.removeElement(var1);
  525.    }
  526.  
  527.    public void fireApplicationStarted() {
  528.       Enumeration var1 = this.listeners.elements();
  529.  
  530.       while(var1.hasMoreElements()) {
  531.          ApplicationListener var2 = (ApplicationListener)var1.nextElement();
  532.          var2.applicationStarted();
  533.       }
  534.  
  535.    }
  536.  
  537.    public void fireApplicationExited() {
  538.       Enumeration var1 = this.listeners.elements();
  539.  
  540.       while(var1.hasMoreElements()) {
  541.          ApplicationListener var2 = (ApplicationListener)var1.nextElement();
  542.          var2.applicationExited();
  543.       }
  544.  
  545.    }
  546.  
  547.    public void fireDocumentOpened(URI var1) {
  548.       Enumeration var2 = this.listeners.elements();
  549.  
  550.       while(var2.hasMoreElements()) {
  551.          ApplicationListener var3 = (ApplicationListener)var2.nextElement();
  552.          var3.documentOpened(var1);
  553.       }
  554.  
  555.    }
  556.  
  557.    public void fireDocumentSaved(URI var1) {
  558.       Enumeration var2 = this.listeners.elements();
  559.  
  560.       while(var2.hasMoreElements()) {
  561.          ApplicationListener var3 = (ApplicationListener)var2.nextElement();
  562.          var3.documentSaved(var1);
  563.       }
  564.  
  565.    }
  566.  
  567.    public void fireDocumentClosed(URI var1) {
  568.       Enumeration var2 = this.listeners.elements();
  569.  
  570.       while(var2.hasMoreElements()) {
  571.          ApplicationListener var3 = (ApplicationListener)var2.nextElement();
  572.          var3.documentClosed(var1);
  573.       }
  574.  
  575.    }
  576.  
  577.    // $FF: synthetic method
  578.    static Class class$(String var0) {
  579.       try {
  580.          return Class.forName(var0);
  581.       } catch (ClassNotFoundException var2) {
  582.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  583.       }
  584.    }
  585.  
  586.    // $FF: synthetic method
  587.    static ApplicationPreferences access$0(BaseApplication var0) {
  588.       return var0.prefs;
  589.    }
  590.  
  591.    // $FF: synthetic method
  592.    static void access$1(BaseApplication var0, int var1) {
  593.       var0.updateToolBarView(var1);
  594.    }
  595. }
  596.